package uf.audit.demo.interceptor;

import javax.servlet.http.HttpServletRequest;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

import uf.audit.tax.platform.core.db.DBProFacotry;
import uf.audit.tax.platform.util.Utils;

public class LogInterceptor implements Interceptor {
	public void intercept(Invocation ai) {
		ai.invoke();
		Controller controller = ai.getController();
		String userId = Utils.getUserId(controller);
		if (userId == "-1")
			return;
		String actionKey = ai.getActionKey();
		if (actionKey.indexOf("pub/noop") != -1)
			return;
		HttpServletRequest request = controller.getRequest();
		String queryStr = request.getQueryString();
		if (queryStr == null)
			queryStr = "";
		if (queryStr.length() > 2000) {
			queryStr = queryStr.substring(0, 2000);
		}
		String method = request.getMethod();
		DBProFacotry.getPro().update(
				"insert into tax_sys_log(tax_sys_log_id, actionKey, userid, logtime, querystr, method) values (tax_sys_log_seq.nextval, ?, ?, sysdate, ?, ?)",
				actionKey, userId, queryStr, method);
	}
}